package com.jc.common.util;

import java.awt.Menu;
import java.util.Date;

/**
 * 内存序列，用于对并发要求不是非常高的有意义ID生成,可用于订单ID，支付ID，生成，可以生成明文时间戳,  有容量限制,每5秒,生成100000个号码
 * @author Administrator
 *
 */

public class MemoryNumber {
	static int  count = 0;
	static long countInitTime = 0l;
	
	static int initMaxTime = 4000; //每五份开始重新计数
	static int maxCount = 999000;
	

	
	public static String getKey() {
		
		Date current = new Date();
		if((current.getTime() - MemoryNumber.countInitTime) > initMaxTime ) {
			MemoryNumber.countInitTime = new Date().getTime();
			MemoryNumber.count = 0;
		}
		MemoryNumber.count += 1;
		
		if(MemoryNumber.count > MemoryNumber.maxCount) {
			return "";
		}
		
		if(String.valueOf(MemoryNumber.count).length() == 1) {
			return "00000" + MemoryNumber.count;
		}
		if(String.valueOf(MemoryNumber.count).length() == 2) {
			return "0000" + MemoryNumber.count;
				}
		if(String.valueOf(MemoryNumber.count).length() == 3) {
			return "000" + MemoryNumber.count;
		}
		if(String.valueOf(MemoryNumber.count).length() == 4) {
			return "00" + MemoryNumber.count;
		}
		if(String.valueOf(MemoryNumber.count).length() == 5) {
			return "0" + MemoryNumber.count;
		}
		
		return String.valueOf(MemoryNumber.count);
	}
	
	
	
	
	
	
	public static void main(String[] args) throws Exception {
		
		
		for(int i = 0 ;  i < 100000000 ; i++) {
			
		}
	}
	
	
	
	

}
